package org.genntii.warehousesystem.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.genntii.warehousesystem.common.Result;
import org.genntii.warehousesystem.domain.dto.EmployeeDTO;
import org.genntii.warehousesystem.domain.dto.EmployeeRegisterDTO;
import org.genntii.warehousesystem.domain.dto.LoginDTO;
import org.genntii.warehousesystem.service.EmployeeService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "员工接口")
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    @Operation(summary = "注册",description = "员工入职注册管理员账号")
    @PostMapping("/v1/register")
    public Result register(@RequestBody EmployeeRegisterDTO employeeRegisterDTO){
        employeeService.register(employeeRegisterDTO);
        return Result.success();
    }

    @Operation(summary = "登录")
    @PostMapping("/login")
    public Result<Map<Object,Object>> login(@RequestBody LoginDTO loginDTO){
        return Result.success(employeeService.login(loginDTO));
    }

    @Operation(summary = "测试接口")
    @GetMapping("/test")
    public String test(HttpServletRequest request){
        int id = (int) request.getAttribute("id");
        return "你好"+id;
    }

    @Operation(summary = "更新员工数据")
    @PostMapping("/v1/update")
    public Result update(@RequestBody EmployeeDTO employeeDTO){
        employeeService.update(employeeDTO);
        return Result.success();
    }

    @Operation(summary = "离职")
    @Parameter(name = "id",description = "员工id",required = true,in = ParameterIn.QUERY)
    @GetMapping("/v1/term")
    public Result term(@RequestParam("id")int id){
        employeeService.term(id);
        return Result.success();
    }


}
